package cn.stylefeng.guns.modular.eruser.controller;

import cn.stylefeng.guns.core.annotion.BusinessLog;
import cn.stylefeng.guns.core.enums.LogAnnotionOpTypeEnum;
import cn.stylefeng.guns.core.pojo.response.ResponseData;
import cn.stylefeng.guns.core.pojo.response.SuccessResponseData;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import cn.stylefeng.guns.modular.eruser.service.ErUserService;
import cn.stylefeng.guns.modular.eruser.model.param.ErUserParam;

import javax.annotation.Resource;

/**
 * 用户表 控制器
 *
 * @author: w
 * @date: 2021/06/16 16:27
 */
@RestController
public class ErUserController {

    @Resource
    private ErUserService erUserService;

    /**
     * 分页查询用户表
     *
     * @author w
     * @date 2021/06/16 16:27
     */
    @GetMapping("/erUser/page")
    @BusinessLog(title = "用户_条件查询", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData page(ErUserParam erUserParam) {
        return new SuccessResponseData(erUserService.page(erUserParam));
    }

    /**
     * 获取全部用户表
     *
     * @author w
     * @date 2021/06/16 16:27
     */
    @GetMapping("/erUser/list")
    @BusinessLog(title = "用户表_查询所有", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData list(ErUserParam erUserParam) {
        return new SuccessResponseData(erUserService.list(erUserParam));
    }

    /**
     * 查看详情用户表
     *
     * @author w
     * @date 2021/06/16 16:27
     */
    @GetMapping("/erUser/detail")
    @BusinessLog(title = "用户表_查看详情", opType = LogAnnotionOpTypeEnum.DETAIL)
    public ResponseData detail(@Validated(ErUserParam.detail.class) ErUserParam erUserParam) {
        return new SuccessResponseData(erUserService.detail(erUserParam));
    }

    /**
     * 添加用户表
     *
     * @author w
     * @date 2021/06/16 16:27
     */
    @PostMapping("/erUser/add")
    @BusinessLog(title = "用户_增加", opType = LogAnnotionOpTypeEnum.ADD)
    public ResponseData add(@RequestBody @Validated(ErUserParam.add.class) ErUserParam erUserParam) {
        erUserService.add(erUserParam);
        return new SuccessResponseData();
    }

    /**
     * 删除用户表
     *
     * @author w
     * @date 2021/06/16 16:27
     */
    @PostMapping("/erUser/delete")
    @BusinessLog(title = "用户表_删除", opType = LogAnnotionOpTypeEnum.DELETE)
    public ResponseData delete(@RequestBody @Validated(ErUserParam.delete.class) ErUserParam erUserParam) {
        erUserService.delete(erUserParam);
        return new SuccessResponseData();
    }

    /**
     * 编辑用户表
     *
     * @author w
     * @date 2021/06/16 16:27
     */
    @PostMapping("/erUser/edit")
    @BusinessLog(title = "用户_修改信息", opType = LogAnnotionOpTypeEnum.EDIT)
    public ResponseData edit(@RequestBody @Validated(ErUserParam.edit.class) ErUserParam erUserParam) {
        erUserService.edit(erUserParam);
        return new SuccessResponseData();
    }

    @PostMapping("/erUser/updateAvatar")
    @BusinessLog(title = "用户_修改信息", opType = LogAnnotionOpTypeEnum.EDIT)
    public ResponseData updateAvatar(@RequestBody ErUserParam erUserParam) {
        erUserService.updateAvatar(erUserParam);
        return new SuccessResponseData();
    }


}
